package com.hmall.controller;

import com.hdmall.business.common.common.ServerResponse;
import com.hdmall.business.common.util.JsonUtils;
import com.hmall.model.SysUser;
import com.hmall.service.BiUserActionHistoryService;
import com.hmall.vo.BiActionHisParamsClientVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("bi/")
@Api(value = "bi操作API", description = "bi操作API说明")
public class BiController {

    @Autowired
    private BiUserActionHistoryService actionHistoryService;

    @Autowired
    private BiUserActionHistoryService biUserActionHistoryService;


    /**
     * 获取用户历史信息
     *
     * @return
     */
    @GetMapping("getUserOderItems")
    @ApiOperation(value = "获取用户历史")
    public ServerResponse<List> getUserOderItems() {

        return biUserActionHistoryService.selectThreeMonths();
    }

    /**
     * 获取用户历史信息
     *
     * @return
     */
    @GetMapping("actionHistoryBiInsert")
    @ApiOperation(value = "记录用户历史")
    public ServerResponse actionHistoryBiInsert(String ip, String user_agent, String user, String userRoleId, String userRoleName, String action, String actionUrl, String content) {

        BiActionHisParamsClientVo biActionHisParamsClientVo = new BiActionHisParamsClientVo();
        biActionHisParamsClientVo.setIp(ip);
        biActionHisParamsClientVo.setUserAgent(user_agent);
        SysUser user1 = JsonUtils.jsonStrToObject(user, SysUser.class);
        biActionHisParamsClientVo.setUser(user1);
        biActionHisParamsClientVo.setAction(action);
        biActionHisParamsClientVo.setActionUrl(actionUrl);
        biActionHisParamsClientVo.setContent(content);
        if (userRoleId != null) {
            biActionHisParamsClientVo.setUserRoleId(Integer.parseInt(userRoleId));
        }
        if (userRoleName != null) {
            biActionHisParamsClientVo.setUserRoleName(userRoleName);
        }
        //用户访问记录
        return actionHistoryService.insertActionHisByClient(biActionHisParamsClientVo);
    }


}
